<template>
  <div class="app-container">

    <!--查询列-->
    <el-form v-show="showSearch" ref="queryForm" :model="queryParams" :inline="true" label-width="68px">
      <el-form-item label="名称" prop="name">
        <el-input v-model="queryParams.name" placeholder="名称" clearable class="filter-item" @keyup.enter.native="handleFilter" />
      </el-form-item>
      <el-form-item label="朝代" prop="dynasty">
        <el-input v-model="queryParams.dynasty" placeholder="朝代" clearable class="filter-item" @keyup.enter.native="handleFilter" />
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!--操作列-->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button v-hasPermi="['poetry:author:add']" type="primary" icon="el-icon-plus" size="mini"  @click="handleAdd">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button v-hasPermi="['poetry:author:edit']" type="success" icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button v-hasPermi="['poetry:author:remove']" type="danger" icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete">删除</el-button>
      </el-col>
      <right-toolbar :show-search.sync="showSearch" @queryTable="getList" />
    </el-row>

    <!--数据表列-->
    <el-table :key="tableKey" v-loading="listLoading" :data="list" fit highlight-current-row style="width: 100%;" @sort-change="sortChange">
      <el-table-column label="序号" width="100" type="index" align="center"/>
      <el-table-column label="名称" width="120" prop="name"/>
      <el-table-column label="朝代" width="120" prop="dynasty">
        <template slot-scope="scope"><dict-tag :options="dict.type.poetry_dynasty" :value="scope.row.dynasty"/></template>
      </el-table-column>
      <el-table-column label="出生日" width="200">
        <template slot-scope="scope"><span>{{ scope.row.birthYear }}年 ~ {{ scope.row.deathYear }}年</span></template>
      </el-table-column>
      <!-- <el-table-column label="简介" width="300" prop="shortDesc"/> -->
      <el-table-column label="描述" min-width="800" prop="longDesc"/>
      <el-table-column label="操作" align="center" width="150" class-name="small-padding fixed-width" fixed="right">
        <template slot-scope="{row,$index}">
          <el-button type="text" size="mini" icon="el-icon-edit" @click="handleUpdate(row)">编辑</el-button>
          <el-button type="text" size="mini" icon="el-icon-delete" @click="handleDelete(row,$index)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!--分页列-->
    <pagination v-show="total>0" :total="total" :page.sync="queryParams.page" :limit.sync="queryParams.limit" @pagination="getList" />
  </div>
</template>

<script>
import { tableInfo, crudUtil, sortUtil } from '@/utils/future/toolkit'
import { fetchAuthorList } from '@/api/poetry'
import waves from '@/directive/waves' // waves directive
import Pagination from '@/components/Pagination' // secondary package based on el-pagination
export default {
  name: 'PoetryAuthor',
  dicts: ['poetry_dynasty'],
  components: { Pagination },
  directives: { waves },
  data() {
    const tableData = {
      idKey: 'id',
      showSearch: true,// 显示搜索条件
      queryParams: {      // 搜索条件
        name: undefined,
        dynasty: undefined
      },
      indexMethod: 1, // 列表序号
      ids: [],  // 选中数组
      single: true,  // 非单个禁用
      multiple: true, // 非多个禁用
      title: '',
      purchOrder: { timelineList: [] },
      form: { id: '', approvalStatus: '', approvelResult: '', remark: '' }
    }
    return Object.assign(tableData, tableInfo)
  },
  created() {
    this.getList()
  },
  methods: {
    getList() {
      var that = this
      const queryParams = that.addDateRange(this.queryParams)
      that.queryParams = queryParams
      crudUtil.getList(that, fetchAuthorList)
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.promotionDate = []
      this.resetForm('queryForm')
      this.handleQuery()
    },

    // 多选框选中数据
    handleSelectionChange(selection) {
      this.refundData = selection
      this.ids = selection.map(item => item.id)
      this.single = selection.length != 1
      this.multiple = !selection.length
    },

    // 重置表单
    reset() {
      this.form = { id: '', approvalStatus: '', approvelResult: '', remark: '' }
    },
    /** 新增按钮操作 */
    handleAdd() {

    },
    /** 修改按钮操作 */
    handleUpdate(row) {

    },
    /** 删除按钮操作 */
    handleDelete(row) {

    },
    sortChange(data) {
      const { prop, order } = data
      if (prop === 'id') {
        sortUtil.sortByID(order)
      }
    }


  }
}
</script>
<style>


</style>
